import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:photo_frame/router/router_context.dart';

class NewScheduleSuccessfulDialog extends StatefulWidget {
  const NewScheduleSuccessfulDialog({super.key});

  @override
  State<StatefulWidget> createState() => NewScheduleSuccessfulState();
}

class NewScheduleSuccessfulState extends State<NewScheduleSuccessfulDialog>
    with SingleTickerProviderStateMixin {
  late AnimationController _controller;
  late Animation<double> _animation;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: Duration(milliseconds: 500),
      vsync: this,
    );
    _animation = Tween<double>(begin: 0, end: 1).animate(_controller);
    _controller.forward();
    Future.delayed(Duration(seconds: 3), () {
      if (mounted) {
        ARouter.instance.pagePop();
      }
    });
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return CupertinoButton(
      padding: EdgeInsets.zero,
      onPressed: () {
        ARouter.instance.pagePop();
      },
      child: Dialog(
          backgroundColor: Colors.transparent,
          child: Center(
            child: AnimatedBuilder(
              animation: _animation,
              builder: (BuildContext context, Widget? child) {
                return Opacity(
                  opacity: _animation.value,
                  child: SizedBox(
                    width: double.infinity,
                    child: AspectRatio(
                      aspectRatio: 1,
                      child: Image.asset(
                          "images/icon_create_schedule_success.png"),
                    ),
                  ),
                );
              },
            ),
          )),
    );
  }
}
